package com.jack.thinking.thread.core._4;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class SimpleReetrantLock {
	public static void main(String[] args) {
		MyService service = new MyService();
		new Thread() {
			public void run() {
				service.testMethod();
			};
		}.start();
		new Thread() {
			public void run() {
				service.testMethod();
			};
		}.start();
		new Thread() {
			public void run() {
				service.testMethod();
			};
		}.start();
		new Thread() {
			public void run() {
				service.testMethod();
			};
		}.start();
		new Thread() {
			public void run() {
				service.testMethod();
			};
		}.start();
	}
}

class MyService{
	private Lock lock = new ReentrantLock();
	
	public void testMethod() {
		lock.lock();
		for (int i = 0; i < 5; i++) {
			System.out.println(Thread.currentThread().getName() + i);
		}
		lock.unlock();
	}
}